﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Dqs_BLL;
using Dqs_DAL;
using Model;
using Sunny.UI;
namespace Dqs_UI
{
	public partial class frmUpdateAdmin : UIForm
	{
		public frmUpdateAdmin(int id)
		{
			InitializeComponent();
			this.Id = id;
		}

		int Id { get; set; }
		Admin_BLL admin_BLL = new Admin_BLL();

		private void frmUpdateAdmin_Load(object sender, EventArgs e)
		{
			AdminInfo adminInfo = admin_BLL.GetAdmins().Where(a => a.Id == Id).FirstOrDefault()!;
			txtUserName.Text = adminInfo.UserName;
			txtPwd.Text = adminInfo.Password;
			txtFullName.Text = adminInfo.FullName;
			txtPhone.Text = adminInfo.Phone;
		}

		private void uiButton2_Click(object sender, EventArgs e)
		{
			frmUpdateAdmin_Load(this, e);
		}

		private void uiButton1_Click(object sender, EventArgs e)
		{
			AdminInfo adminInfo = new AdminInfo();
			adminInfo.Id = Id;
			adminInfo.UserName = txtUserName.Text.Trim();
			adminInfo.Password = txtPwd.Text.Trim();
			adminInfo.FullName = txtFullName.Text.Trim();
			adminInfo.Phone = txtPhone.Text.Trim();
			
			if (admin_BLL.UpdateAdminInfoById(adminInfo))
			{
				DialogResult = DialogResult.OK;
			}
			else
			{
				MessageBox.Show("请检查输入内容是否正确！");
			}
		}
	}
}
